<?php

// Utilities
require("utilities/materiel.php") ;

/*if ($_GET['action']=='delete'){
    if(isset ($_GET['confirm']) && $_GET['confirm']==y){
        connect();
        $requete = "DELETE FROM Materiel WHERE id={$_GET['id']}";
        executerRequete($requete, $GLOBALS['debug']);
        $requete = "DELETE FROM Pret WHERE materiel={$_GET['id']}";
        executerRequete($requete, $GLOBALS['debug']);
        echo <<<END
        <div>
            Suppression effectuée.
            <a href="index.php?page=materiel">Retour</a>
	</div>
END;
    }
    else{
	connect();
	$requete = "SELECT * FROM Materiel WHERE id={$_GET['id']}";
        $reponse = executerRequete($requete, $GLOBALS["debug"]);
	if ($donnees1 = mysql_fetch_array($reponse)) {
            $materiel_nom = $donnees1['nom'];

	}
	echo <<<END
        <div>
            Voulez vous supprimer {$materiel_nom} ?
            <a href="index.php?page=materiel&amp;action=delete&amp;id={$_GET['id']}&amp;confirm=y">Oui</a>
            <a href="index.php?page=materiel">Non</a>
	</div>
END;
	mysql_close();
    }
}
else*/

require("ajax/emprunterRendreMateriel.php") ;

if (empty($_GET['id_matos']))
{
    alert ("Aucun matériel spécifié.");
    return ;
}


connect();
$requete = "SELECT * FROM Materiel WHERE id={$_GET['id_matos']}";
$reponse = executerRequete($requete, $GLOBALS["debug"]);

if ($donnees1 = mysql_fetch_array($reponse))
{
    echo <<<END
    <h2>Description de {$donnees1['nom']} :</h2>
END;

    if (niveauOK(2))
        echo "<a class=\"edition\" href=\"index.php?page=updateMateriel&id={$_GET['id_matos']}\">Editer</a><br/>" ;
    echo <<< END
    <p>{$donnees1['description']}</p>
    <h2>Historique des prêts de {$donnees1['nom']} :</h2>
END;
    $requete2 = "SELECT Pret.*, User.nom, User.prenom FROM Pret LEFT JOIN User ON User.pseudo=Pret.emprunteur WHERE Materiel={$donnees1['id']} ORDER BY date_emprunt DESC";
    $reponse2 = executerRequete($requete2, $GLOBALS["debug"]);

    echo <<<END
    <table width="600" border="1">
        <tr>
            <th scope="col">Emprunteur</th>
            <th scope="col">Date</th>
        </tr>
END;

    while ($donnees2 = mysql_fetch_array($reponse2))
    {

        $date_emprunt = date('d/m/Y \(H\hi\m\i\ns\s\)',convertirDate($donnees2['date_emprunt']));
        $date_retour = date('d/m/Y \(H\hi\m\i\ns\s\)',convertirDate($donnees2['date_retour']));

        echo <<<END
        <tr>
            <td><a class="edition" href="index.php?page=user&pseudo={$donnees2['emprunteur']}">{$donnees2['prenom']} {$donnees2['nom']}</a></td>
END;
        if($donnees2['date_retour']==0){
            echo "<td>Depuis le {$date_emprunt}</td>";
        }else{
            echo "<td>De {$date_emprunt} à {$date_retour}</td>";
        }

        echo "</tr>";

    }

        echo "</table>";
}
mysql_close();


?>


